<!--  -->
<template>
  <div class="app-container">
    <div class="formDiv">
      <el-form ref="form" :inline="true" :model="form" label-width="130px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="机构名称">
              <!-- @blur="inputBlur" -->
              <el-select
                v-model="form.hospital_id"
                clearable
                filterable
                remote
                :remote-method="remoteMethod"
                @change="handleChange"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in hospitalNameList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="入驻时间">
              <el-date-picker
                v-model="dates"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="daterange"
                range-separator="-"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item>
              <el-button style="margin-left:60px" type="primary" @click="handleSearch">查询</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 主页列表 -->
    <div v-loading="tableLoading" class="listDiv">
      <el-table :data="tableData" class="tableData" style="width: 100%">
        <el-table-column
          fixed
          type="index"
          label="序号"
          width="50"
          align="center"
          :index="table_index"
        />
        <el-table-column prop="hospital_name" label="机构名称" align="center" />
        <el-table-column prop="bank_name" label="地区" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.province_name || ''}}{{scope.row.city_name || ''}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="org_realname" label="机构负责人" align="center" />
        <el-table-column prop="org_phone" label="机构负责人手机号" align="center" />
        <el-table-column prop="balance" label="账户余额" align="center" />
        <el-table-column prop="withdraw" label="账户累计提现金额" align="center" />
        <el-table-column prop="settled_amount" label="入驻金额" align="center" />
        <el-table-column prop="org_signtime" label="机构入驻时间" align="center" />
      </el-table>
      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            :current-page="form.page"
            :page-sizes="page_sizes"
            :page-size="form.size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page_totals"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  hospitalList,
  hospitalDel,
  getHospitalName,
  onShelf,
} from "@/api/couponList";
//
import { accountList, getOrgList } from "@/api/accountMange";
export default {
  name: "accountMange",
  data() {
    return {
      form: {
        hospital_id: "",
        start_time: "",
        end_time: "",
        page: 1,
        size: 10,
      },
      hospitalNameList: [],
      hospitalArr: [],
      tableData: [],
      page_totals: 0,
      page_sizes: [10, 30, 50, 100],
      tableLoading: false,
      dates: null,
    };
  },

  components: {},
  watch: {
    // 入驻时间
    dates(val) {
      this.form.start_time = val ? val[0] : "";
      this.form.end_time = val ? val[1] : "";
    },
  },
  mounted() {
    this.getList(this.form);
    this.getHosName();
  },

  methods: {
    // 序号
    table_index(index) {
      return (this.form.page - 1) * this.form.size + index + 1;
    },
    // 路由跳转
    toRoutes(name, id, type) {
      const route = { path: name, query: { id: id, type: type } };
      this.$router.push(route);
    },
    // 获取列表
    async getList(opt) {
      this.tableLoading = true;
      let res = await accountList(opt);
      if (res.data.code == 200) {
        this.tableLoading = false;
        this.tableData = res.data.data;
        this.page_totals = res.data.meta.total;
      } else {
        this.tableLoading = false;
        this.errorStatus(res.data.msg);
      }
    },
    // 获取机构名称
    async getHosName() {
      let res = await getOrgList();
      if (res.data.code == 200) {
        let resData = res.data.data;
        this.hospitalNameList = resData;
        this.hospitalArr = resData;
      } else {
        this.errorStatus(res.data.msg);
      }
    },
    // 远程搜索获取机构名称
    remoteMethod(query) {
      const data = { keyword: query };
      if (query != "") {
        getOrgList(data).then((res) => {
          if (res.data.code == 200) {
            let resData = res.data.data;
            if (resData.length > 0) {
              // console.log(8888);
              this.hospitalNameList = resData;
            }
          } else {
            this.errorStatus(res.data.msg);
          }
        });
      } else {
        this.hospitalNameList = this.hospitalArr;
      }
    },
    // 机构名称失焦
    inputBlur() {
      this.hospitalNameList = this.hospitalArr;
    },
    // 机构名称下拉切换
    handleChange(e) {
      // console.log("e", e);
      this.form.hospital_id = e;
      this.getHosName();
    },
    // 查询
    handleSearch() {
      this.form.page = 1;
      this.getList(this.form);
    },
    // 改变页面条数
    handleSizeChange(val) {
      this.form.size = val;
      this.getList(this.form);
    },
    // 选择页数
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form);
    },
    // 失败状态弹窗
    errorStatus(txt) {
      this.eleMsg(txt, "error");
    },
    // 成功状态弹窗
    warnStatus(txt, status) {
      this.eleMsg(txt, status);
    },
    // 弹窗组件
    eleMsg(txt, status) {
      this.$message({
        showClose: true,
        message: txt,
        type: status,
      });
    },
  },
};
</script>
<style  scoped>
.pagesCon {
  height: 40px;
  margin-top: 20px;
}
.pagesCon > div {
  float: right;
}
</style>